
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/*makes the Boards, sets string name
 * sets chosen icon of player*/

public class Player2Ui extends JFrame {
	
	playerPanelUi playerPanelUi;

	private JPanel contentPane;
	private JTextField txtName1;
	private JTextField txtName2;
	private JTextField txtName3;
	private JTextField txtName4;
	private JTextField txtName5;
	private JTextField txtName6;
	private JTextField txtName7;
	private JTextField txtName8;
	
	private Player[] play;
	private int playerCount;
	private int currentPlayerCount;
	private int tempPlayerCount;
	private JButton btnPick1, btnPick2, btnPick3, btnPick4, btnPick5, btnPick6, btnPick7, btnPick8;
	
	public Player2Ui(int playerCnt) {
		this.currentPlayerCount = 0;
		this.playerCount=playerCnt;
		this.play = new Player[playerCount];
		this.tempPlayerCount = 0;
		
		for(currentPlayerCount=0;currentPlayerCount < playerCount;currentPlayerCount++) {
			this.play[currentPlayerCount] = new Player(currentPlayerCount);
		}

		
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 550, 433);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBackground(new Color(216, 191, 216));
		panel.setBounds(0, 0, 538, 384);
		contentPane.add(panel);
		panel.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setIcon(new ImageIcon(Player2Ui.class.getResource("/images/GREENBIG.jpg")));
		lblNewLabel.setBounds(133, 168, 102, 87);
		panel.add(lblNewLabel);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon(Player2Ui.class.getResource("/images/BigBlueSmiley.jpeg")));
		label.setBounds(0, 168, 102, 87);
		panel.add(label);
		
		JLabel label_1 = new JLabel("");
		label_1.setIcon(new ImageIcon(Player2Ui.class.getResource("/images/boybig.jpg")));
		label_1.setBounds(0, 0, 102, 93);
		panel.add(label_1);
		
		JLabel label_2 = new JLabel("");
		label_2.setIcon(new ImageIcon(Player2Ui.class.getResource("/images/girl.jpg")));
		label_2.setBounds(133, 0, 102, 93);
		panel.add(label_2);
		
		JLabel label_3 = new JLabel("");
		label_3.setIcon(new ImageIcon(Player2Ui.class.getResource("/images/yellowbig.jpg")));
		label_3.setBounds(265, 164, 102, 95);
		panel.add(label_3);
		
		JLabel label_4 = new JLabel("");
		label_4.setIcon(new ImageIcon(Player2Ui.class.getResource("/images/pinkBig.jpg")));
		label_4.setBounds(397, 168, 102, 87);
		panel.add(label_4);
		
		JLabel label_5 = new JLabel("");
		label_5.setIcon(new ImageIcon(Player2Ui.class.getResource("/images/heartredbig.jpg")));
		label_5.setBounds(265, 0, 102, 93);
		panel.add(label_5);
		
		JLabel label_6 = new JLabel("");
		label_6.setIcon(new ImageIcon(Player2Ui.class.getResource("/images/greenhbig.jpeg")));
		label_6.setBounds(397, 0, 102, 93);
		panel.add(label_6);
		
		btnPick1 = new JButton("Piliin");
		btnPick1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				btnPick1ActionPerformed(event);
			}
		});
		btnPick1.setBounds(0, 113, 102, 23);
		panel.add(btnPick1);
		
		btnPick2 = new JButton("Piliin");
		btnPick2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				btnPick2ActionPerformed(event);

			}
		});
		btnPick2.setBounds(133, 113, 102, 23);
		panel.add(btnPick2);
		
		btnPick3 = new JButton("Piliin");
		btnPick3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				btnPick3ActionPerformed(event);
			}
		});
		btnPick3.setBounds(264, 113, 103, 23);
		panel.add(btnPick3);
		
		btnPick4 = new JButton("Piliin");
		btnPick4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				btnPick4ActionPerformed(event);

			}
		});
		btnPick4.setBounds(397, 113, 99, 23);
		panel.add(btnPick4);
		
		btnPick5 = new JButton("Piliin");
		btnPick5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				btnPick5ActionPerformed(event);

			}
		});
		btnPick5.setBounds(0, 276, 102, 23);
		panel.add(btnPick5);
		
		btnPick6 = new JButton("Piliin");
		btnPick6.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				btnPick6ActionPerformed(event);
			}
		});
		btnPick6.setBounds(133, 276, 102, 23);
		panel.add(btnPick6);
		
		btnPick7 = new JButton("Piliin");
		btnPick7.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				btnPick7ActionPerformed(event);
			}
		});
		btnPick7.setBounds(264, 276, 103, 23);
		panel.add(btnPick7);
		
		btnPick8 = new JButton("Piliin");
		btnPick8.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				btnPick8ActionPerformed(arg0);
			}
		});
		btnPick8.setBounds(397, 276, 102, 23);
		panel.add(btnPick8);
		
		txtName1 = new JTextField();
		txtName1.setBorder(new LineBorder(new Color(164, 185, 127), 2, true));
		txtName1.setBounds(0, 92, 102, 20);
		panel.add(txtName1);
		txtName1.setColumns(10);
		
		txtName2 = new JTextField();
		txtName2.setBorder(new LineBorder(new Color(164, 185, 127), 2, true));
		txtName2.setColumns(10);
		txtName2.setBounds(133, 92, 102, 20);
		panel.add(txtName2);
		
		txtName3 = new JTextField();
		txtName3.setBorder(new LineBorder(new Color(164, 185, 127), 2, true));
		txtName3.setColumns(10);
		txtName3.setBounds(265, 92, 102, 20);
		panel.add(txtName3);
		
		txtName4 = new JTextField();
		txtName4.setBorder(new LineBorder(new Color(164, 185, 127), 2, true));
		txtName4.setColumns(10);
		txtName4.setBounds(397, 92, 102, 20);
		panel.add(txtName4);
		
		txtName5 = new JTextField();
		txtName5.setBorder(new LineBorder(new Color(164, 185, 127), 2, true));
		txtName5.setColumns(10);
		txtName5.setBounds(0, 255, 102, 20);
		panel.add(txtName5);
		
		txtName6 = new JTextField();
		txtName6.setBorder(new LineBorder(new Color(164, 185, 127), 2, true));
		txtName6.setColumns(10);
		txtName6.setBounds(133, 255, 102, 20);
		panel.add(txtName6);
		
		txtName7 = new JTextField();
		txtName7.setBorder(new LineBorder(new Color(164, 185, 127), 2, true));
		txtName7.setColumns(10);
		txtName7.setBounds(265, 255, 102, 20);
		panel.add(txtName7);
		
		txtName8 = new JTextField();
		txtName8.setBorder(new LineBorder(new Color(164, 185, 127), 2, true));
		txtName8.setColumns(10);
		txtName8.setBounds(397, 255, 102, 20);
		panel.add(txtName8);
		
		JButton btnNewButton = new JButton("LARO NA!!");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(tempPlayerCount == play.length){
					BoardUi page = new BoardUi(play);//array
				    page.setVisible(true);
				    setVisible(false);	
				}else{
					JOptionPane.showMessageDialog(null,"Kulang ang Players, add ka pa!");
				}
			}
		});
		btnNewButton.setBounds(205, 332, 92, 41);
		panel.add(btnNewButton);
	}
	
	public void btnPick1ActionPerformed(ActionEvent event) {
		if(tempPlayerCount <= play.length){
			play[tempPlayerCount].setIcon("/images/boyToken.jpg");
			play[tempPlayerCount].setName(txtName1.getText());
			btnPick1.setEnabled(false);
			tempPlayerCount++;
		}else{
			JOptionPane.showMessageDialog(null,"NAABOT NIYO NA ANG PINAKAMADAMING MANLALARO!! PINDUTIN ANG LARO NA!!");
		}
	}
	
	public void btnPick2ActionPerformed(ActionEvent event) {
		if(tempPlayerCount <play.length){
			play[tempPlayerCount].setIcon("/images/girlToken.jpg");
			play[tempPlayerCount].setName(txtName2.getText());
			btnPick2.setEnabled(false);
			tempPlayerCount++;
		}else{
			JOptionPane.showMessageDialog(null,"NAABOT NIYO NA ANG PINAKAMADAMING MANLALARO!! PINDUTIN ANG LARO NA!!");
		}
	}
	
	public void btnPick3ActionPerformed(ActionEvent event) {
		if(tempPlayerCount < play.length){
			play[tempPlayerCount].setIcon("/images/heartToken.jpg");
			play[tempPlayerCount].setName(txtName3.getText());
			btnPick3.setEnabled(false);
			tempPlayerCount++;
		}else{
			JOptionPane.showMessageDialog(null,"NAABOT NIYO NA ANG PINAKAMADAMING MANLALARO!! PINDUTIN ANG LARO NA!!");
		}
	}
	
	public void btnPick4ActionPerformed(ActionEvent event) {
		if(tempPlayerCount < play.length){
			play[tempPlayerCount].setIcon("/images/greenheartToken.jpg");
			play[tempPlayerCount].setName(txtName4.getText());
			btnPick4.setEnabled(false);
			tempPlayerCount++;
		}else{
			JOptionPane.showMessageDialog(null,"NAABOT NIYO NA ANG PINAKAMADAMING MANLALARO!! PINDUTIN ANG LARO NA!!");
		}
	}
	
	public void btnPick5ActionPerformed(ActionEvent event) {
		if(tempPlayerCount < play.length){
			play[tempPlayerCount].setIcon("/images/blueToken.jpg");
			play[tempPlayerCount].setName(txtName5.getText());
			btnPick5.setEnabled(false);
			tempPlayerCount++;
		}else{
			JOptionPane.showMessageDialog(null,"NAABOT NIYO NA ANG PINAKAMADAMING MANLALARO!! PINDUTIN ANG LARO NA!!");
		}
	}
	
	public void btnPick6ActionPerformed(ActionEvent event) {
			if(tempPlayerCount<play.length){
				play[tempPlayerCount].setIcon("/images/greenToken.jpg");
				play[tempPlayerCount].setName(txtName6.getText());
				btnPick6.setEnabled(false);
				tempPlayerCount++;
			}else{
				JOptionPane.showMessageDialog(null,"NAABOT NIYO NA ANG PINAKAMADAMING MANLALARO!! PINDUTIN ANG LARO NA!!");
			}
	}
	
	public void btnPick7ActionPerformed(ActionEvent event) {
		if(tempPlayerCount < play.length){
			play[tempPlayerCount].setIcon("/images/yellowToken.jpg");
			play[tempPlayerCount].setName(txtName7.getText());
			btnPick7.setEnabled(false);
			tempPlayerCount++;
		}else{
			JOptionPane.showMessageDialog(null,"NAABOT NIYO NA ANG PINAKAMADAMING MANLALARO!! PINDUTIN ANG LARO NA!!");
		}
	}
	
	public void btnPick8ActionPerformed(ActionEvent event) {
		if(tempPlayerCount < play.length){
			play[tempPlayerCount].setIcon("/images/pinkToken.jpg");
			play[tempPlayerCount].setName(txtName8.getText());
			btnPick8.setEnabled(false);
			tempPlayerCount++;
		}else{
			JOptionPane.showMessageDialog(null,"NAABOT NIYO NA ANG PINAKAMADAMING MANLALARO!! PINDUTIN ANG LARO NA!!");
		}
	}
}
